<template>
	<view class="box">
		  <!-- <scroll-view
		        scroll-y
		        style="height: 100%; border: 1px solid #ccc;"
		        @scrolltolower="loadMoreData"> -->
		<view class="back" @click="goBack()">
			 <text class="cuIcon-back Back">返回</text>
		</view>
			<scroll-view scroll-x class="bg-white nav" scroll-with-animation :scroll-left="scrollLeft">
		<view class="cu-item" :class="index==TabCur?'text-green cur':''" v-for="(item,index) in list"
		:key="index" @tap="tabSelect" :data-id="index">
		<view class=""  @click="byId(item.id)">
			{{item.name}}
		</view>
		</view>
	</scroll-view>
	<view class="liSt">
		<text class="LIstext">
			{{listText.name}}
		</text>
		<text class="listdesc">
			{{listText.desc}}
		</text>
		
		<view class="contentBox">
		<view class="contBox" v-for="(item,index) in content" :key="index" @click="wyJumpWy(item.id)">
			<view class="">
				<img :src="item.picUrl" alt="" class="contpicUrl" />
			</view>
			<view class="">
				<text class="cBname">
					{{item.name}}
				</text>
				<text class="cBbrief">
					{{item.brief}}
				</text>
				
				<view class="cBmoney">
					<text class="cbmo">￥</text> <text class="retailPrice">{{item.retailPrice}}</text>
					<text class="counterPrice">￥{{item.counterPrice}}</text>
				</view>
			</view>
			
		</view>
		<view class="textCont">
			<text class="">
				没有更多了
			</text>
		</view>
			</view>
	</view>
	<!-- </scroll-view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content:[],
				listText:[],
				name,
				newContent:[],
				num:'',
				max:'',
				page:1,
				pagesize:10,
				content:[],
				listText:[],
				name:'',
				getId:1,
				list:[],
				TabCur: 0,
				scrollLeft: 0
			};
		},
	
		methods: {
			wyJumpWy(prodid){
				// 将 val 转换为 JSON 字符串
				const valStr = encodeURIComponent(JSON.stringify(prodid));
				uni.navigateTo({
					url: `/pages/detail/detail?prodid=${valStr}`
				});
			},
			loadMoreData(){
				 this.page++;
				 console.log(this.page)
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			getNew(){
				//请求的数据
				uni.request({
					url:'http://admin.bsmall.byesame.com/wx/goods/category?id='+this.getId,
					data:{},
					header:{},
					success:(res)=>{
						console.log(res,'请求出来的应用列表'),
						this.list=res.data.data.brotherCategory,
						this.listText=res.data.data.currentCategory
						console.log(this.list)
						console.log((this.listText))
						
					}
				})
			},
			getListId(){
				uni.request({
					url:'http://admin.bsmall.byesame.com/wx/goods/list?categoryId='+this.getId+'&page='+this.page+'&limit=10',
					data:{},
					header:{},
					success:(res)=>{
						console.log(res,'请求出来的应用列表wy'),
						this.content=res.data.data.list
						console.log(this.content,"内容")
					}
				})
			},


			byId(val){
				console.log(val)
				this.name=val
				uni.request({
					url:'http://admin.bsmall.byesame.com/wx/goods/list?categoryId='+this.name+'&page='+this.page+'&limit=10',
					data:{},
					header:{},
					success:(res)=>{
						console.log(res,'请求出来的应用列表'),
						this.content=res.data.data.list
						console.log(this.content,"内容")
					}
				}),
				uni.request({
					url:'http://admin.bsmall.byesame.com/wx/goods/category?id='+this.name,
					data:{},
					header:{},
					success:(res)=>{
						console.log(res,'请求出来的应用列表'),
						this.list=res.data.data.brotherCategory,
						this.listText=res.data.data.currentCategory
						console.log(this.list)
						console.log((this.listText))
						this.getId=val,
						this.num=1,
						this.max=1
						
					}
				})
			
			},
			add(){
				uni.request({
					url:'http://admin.bsmall.byesame.com/wx/goods/list?categoryId='+this.getId+'&page='+this.num+'&limit=10',
					data:{},
					header:{},
					success:(res)=>{
						
						console.log(res,'请求出来的应用列表'),
						this.content=this.content.concat(res.data.data.list)
						console.log(this.content,"内容")
					}
				})
			},
		
			goBack(){
				uni.navigateBack ({
					delta:2
				});
			},
			
		},
		// 下滑
				onPageScroll : function(e) {
					console.log("滚动距离为：" + e.scrollTop);
					if(e.scrollTop>=150 && this.num<2){
						this.num=2
						this.max=2
						this.add()
					}
					if(  Math.floor((e.scrollTop-150)/1080) +2>this.num&&Math.floor((e.scrollTop-150)/1080) +2>this.max){
						let pdp=Math.floor((e.scrollTop-150)/1080) +2
						this.num=pdp
						this.max=pdp
						this.add()
					}
				},

		onLoad(option){
			this.getId=option.itemClass 
			console.log(this.getId,'11111')
			this.getNew()
			this.getListId()
			this.byId()
		}
	}
</script>

<style lang="scss" scoped>
@import url(category.css);
	body{
	}
	uni-page-body, uni-page-refresh{
		width: 100%;
		height: 100%;
	}
</style>
